;;; init-projectile.el --- Projectile configuration -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:

(with-eval-after-load 'projectile
  (defun ctrlwei/projectile-find-file (arg)
    "Jump to a project's file using completion.
If prefix arg ARG equal '(4), find file in parent project,
or invalidates the cache."
    (interactive "P")
    (let ((project-dir (projectile-project-root (concat (projectile-project-root) "../"))))
      (if (equal arg '(4))
          (if project-dir
              (projectile-switch-project-by-name project-dir)
            (message "[ctrlwei/projectile-find-file] This repository is not a submodule."))
        (projectile-find-file arg))))

  (setq projectile-completion-system 'default)
  (setq projectile-enable-caching t)
  (setq projectile-use-git-grep t)
  (define-key projectile-mode-map (kbd "C-c p") #'projectile-command-map)
  (define-key projectile-mode-map (kbd "C-c b") #'projectile-switch-to-buffer)
  (define-key projectile-mode-map (kbd "C-c g") #'ctrlwei/projectile-find-file)
  )

(add-hook 'after-init-hook 'projectile-mode)

(with-eval-after-load 'marginalia
  ;; Enable marginalia for some projectile commands
  (add-to-list 'marginalia-command-categories '(projectile-find-file . project-file))
  (add-to-list 'marginalia-command-categories '(projectile-switch-to-buffer . buffer)))

(provide 'init-projectile)
;;; init-projectile.el ends here
